﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using TodoList.ViewModel;
using TodoList.Common;
using System.Windows.Media;

namespace TodoList.Converter
{
    public class TodoConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TodoDeleteBind todoMerget = new TodoDeleteBind();
            todoMerget.Id = values[0] as string;
            todoMerget.TodoViewModel = values[1] as TodoVM;
            return todoMerget;
        }
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }

    public class TodoEditConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TodoBind todoMerget = new TodoBind();
            todoMerget.ObjectType = values[0];
            todoMerget.TodoViewModel = values[1] as TodoVM;
            return todoMerget;
        }
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }

    public class PriorityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int iPri = int.Parse(value.ToString());
            string returnValue = string.Empty;
            switch (iPri)
            {
                case 0:
                    returnValue = Priorities.Immediate.ToString();
                    break;
                case 1:
                    returnValue = Priorities.Medium.ToString();
                    break;
                case 2:
                    returnValue = Priorities.Normal.ToString();
                    break;
                case 3:
                    returnValue = Priorities.Low.ToString();
                    break;
                default:
                    break;
            }
            return returnValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }



    public class StateConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int iState = int.Parse(value.ToString());
            string returnValue = string.Empty;
            switch (iState)
            {
                case 0:
                    returnValue = States.NotStarted.ToString();
                    break;
                case 1:
                    returnValue = States.InProgress.ToString();
                    break;
                case 2:
                    returnValue = States.Completed.ToString();
                    break;
                case 3:
                    returnValue = States.Defered.ToString();
                    break;
                default:
                    break;
            }
            return returnValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class CompleteConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int iState = int.Parse(value.ToString());
            int returnValue = 0;
        //C0 = 0,//DarkRed
        //C25 = 25,//red
        //C50 = 50,//orange
        //C75 = 75,//yellow
        //C100 = 100 // darkgreen
            switch (iState)
            {
                case 0:
                    returnValue = 0;
                    break;
                case 1:
                    returnValue = 25;
                    break;
                case 2:
                    returnValue = 50;
                    break;
                case 3:
                    returnValue = 75;
                    break;
                case 4:
                    returnValue = 100;
                    break;
                default:
                    break;
            }
            return returnValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class CompleteColorConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int iState = int.Parse(value.ToString());
            SolidColorBrush solidColor = Brushes.AliceBlue;            
            switch (iState)
            {
                case 0:
                    solidColor = Brushes.DarkRed;                    
                    break;
                case 1:
                    solidColor = Brushes.Red;
                    break;
                case 2:
                    solidColor = Brushes.Orange;
                    break;
                case 3:
                    solidColor = Brushes.Yellow;
                    break;
                case 4:
                    solidColor = Brushes.DarkGreen;
                    break;
                default:
                    break;
            }
            return solidColor;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class TodoDeleteBind
    {
        public object Id
        {
            get;
            set;
        }
        public TodoVM TodoViewModel
        {
            get;
            set;
        }
    }

    public class TodoBind
    {
        public object ObjectType
        {
            get;
            set;
        }
        public TodoVM TodoViewModel
        {
            get;
            set;
        }
    }
}
